binary '>>' : no operator defined which takes a right-hand operand of type ''

来源:百度知道 编辑:UC知道 时间:2024/06/10 15:37:50
该程序是做矩阵加法的,这错怎么改(我刚学指针)
#include<iostream>
using namespace std;
const int X=3;
const int Y=4;

void MP(int a[X][Y],int b[X][Y])
{
int i=0;int *m;int *n;
*m=a[0][0];
*n=b[0][0];
for(;i<X*Y;i++)
{
*m=(*m++)+(*n++);
}
}

int main(void)
{
int a[X][Y],b[X][Y];
for(int p=0;p<X;p++)
{
cout<<"|";
for(int q=0;q<Y;q++)
{
cout<<" ";
cin>>*(a+p)+q; //有错 no operator defined which takes a right-hand operand of type 'int *' (or there is no acceptable conversion)

}
cout<<" |"<<endl;
}
cout<<"结果为:"<<endl;
cout<<MP<<endl;
return 0;
}

cin>>*(a+p)+q;
改成cin>>*(*(a+p)+q);或者干脆就cin>>a[p][q];

cin>>*(a+p)+q; //有错 no operator defined which takes a right-hand operand of type 'int *' (or there is no acceptable conversion)

改成:

cin>>a[p][q];